// 方式一
//
// 时间：80ms - 72.7%
function letterCombinations(digits) {
  const letterMaps = [
    "",
    "",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz"
  ];
  const letters = digits.split("").map((ele) => {
    return letterMaps[Number(ele)];
  });

  return letters.reduce((ret, current) => {
    return letterProduct(ret, current);
  }, []);

  function letterProduct(letter1, letter2) {
    let ret = [];
    if (letter1.length === 0) {
      ret = letter2.split("");
    }
    for (let n = 0; n < letter1.length; n++) {
      for (let k = 0; k < letter2.length; k++) {
        ret.push(letter1[n] + letter2[k]);
      }
    }
    return ret;
  }
}
console.log(letterCombinations("234"));
